package b.i.h;

import android.os.Handler;
import android.os.Handler.Callback;
import android.os.HandlerThread;
import android.os.Message;
import com.huawei.hms.android.HwBuildEx.VersionCodes;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/* compiled from: SelfDestructiveThread */
public class f {
    public final Object a = new Object();
    public HandlerThread b;
    public Handler c;
    public int d = 0;
    public Callback e = new a();

    /* compiled from: SelfDestructiveThread */
    public class a implements Callback {
        public boolean handleMessage(Message message) {
            int i = message.what;
            if (i == 0) {
                f fVar = f.this;
                synchronized (fVar.a) {
                    if (fVar.c.hasMessages(1)) {
                    } else {
                        fVar.b.quit();
                        fVar.b = null;
                        fVar.c = null;
                    }
                }
                return true;
            } else if (i != 1) {
                return true;
            } else {
                f fVar2 = f.this;
                Runnable runnable = (Runnable) message.obj;
                Objects.requireNonNull(fVar2);
                runnable.run();
                synchronized (fVar2.a) {
                    fVar2.c.removeMessages(0);
                    Handler handler = fVar2.c;
                    handler.sendMessageDelayed(handler.obtainMessage(0), (long) VersionCodes.CUR_DEVELOPMENT);
                }
                return true;
            }
        }
    }

    /* compiled from: SelfDestructiveThread */
    public class b implements Runnable {
        public final /* synthetic */ AtomicReference a;
        public final /* synthetic */ Callable b;
        public final /* synthetic */ ReentrantLock c;
        public final /* synthetic */ AtomicBoolean d;
        public final /* synthetic */ Condition e;

        public b(f fVar, AtomicReference atomicReference, Callable callable, ReentrantLock reentrantLock, AtomicBoolean atomicBoolean, Condition condition) {
            this.a = atomicReference;
            this.b = callable;
            this.c = reentrantLock;
            this.d = atomicBoolean;
            this.e = condition;
        }

        public void run() {
            try {
                this.a.set(this.b.call());
            } catch (Exception unused) {
            }
            this.c.lock();
            try {
                this.d.set(false);
                this.e.signal();
            } finally {
                this.c.unlock();
            }
        }
    }

    /* compiled from: SelfDestructiveThread */
    public interface c<T> {
        void a(T t);
    }

    public f(String str, int i, int i2) {
    }

    public final void a(Runnable runnable) {
        synchronized (this.a) {
            if (this.b == null) {
                HandlerThread handlerThread = new HandlerThread("fonts", 10);
                this.b = handlerThread;
                handlerThread.start();
                this.c = new Handler(this.b.getLooper(), this.e);
                this.d++;
            }
            this.c.removeMessages(0);
            Handler handler = this.c;
            handler.sendMessage(handler.obtainMessage(1, runnable));
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:16:0x004d  */
    /* JADX WARNING: Removed duplicated region for block: B:24:0x0045 A:{SYNTHETIC} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:10:0x003f */
    /* JADX WARNING: Can't wrap try/catch for region: R(5:8|9|10|11|(4:24|13|14|15)(2:16|(1:18)(3:19|20|21))) */
    public <T> T b(java.util.concurrent.Callable<T> r13, int r14) throws java.lang.InterruptedException {
        /*
        r12 = this;
        r7 = new java.util.concurrent.locks.ReentrantLock;
        r7.<init>();
        r8 = r7.newCondition();
        r9 = new java.util.concurrent.atomic.AtomicReference;
        r9.<init>();
        r10 = new java.util.concurrent.atomic.AtomicBoolean;
        r0 = 1;
        r10.<init>(r0);
        r11 = new b.i.h.f$b;
        r0 = r11;
        r1 = r12;
        r2 = r9;
        r3 = r13;
        r4 = r7;
        r5 = r10;
        r6 = r8;
        r0.m496init(r1, r2, r3, r4, r5, r6);
        r12.a(r11);
        r7.lock();
        r13 = r10.get();	 Catch:{ all -> 0x005c }
        if (r13 != 0) goto L_0x0034;
    L_0x002c:
        r13 = r9.get();	 Catch:{ all -> 0x005c }
        r7.unlock();
        return r13;
    L_0x0034:
        r13 = java.util.concurrent.TimeUnit.MILLISECONDS;	 Catch:{ all -> 0x005c }
        r0 = (long) r14;	 Catch:{ all -> 0x005c }
        r13 = r13.toNanos(r0);	 Catch:{ all -> 0x005c }
    L_0x003b:
        r13 = r8.awaitNanos(r13);	 Catch:{ InterruptedException -> 0x003f }
    L_0x003f:
        r0 = r10.get();	 Catch:{ all -> 0x005c }
        if (r0 != 0) goto L_0x004d;
    L_0x0045:
        r13 = r9.get();	 Catch:{ all -> 0x005c }
        r7.unlock();
        return r13;
    L_0x004d:
        r0 = 0;
        r2 = (r13 > r0 ? 1 : (r13 == r0 ? 0 : -1));
        if (r2 <= 0) goto L_0x0054;
    L_0x0053:
        goto L_0x003b;
    L_0x0054:
        r13 = new java.lang.InterruptedException;	 Catch:{ all -> 0x005c }
        r14 = "timeout";
        r13.<init>(r14);	 Catch:{ all -> 0x005c }
        throw r13;	 Catch:{ all -> 0x005c }
    L_0x005c:
        r13 = move-exception;
        r7.unlock();
        throw r13;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.h.f.b(java.util.concurrent.Callable, int):java.lang.Object");
    }
}
